package extract.document;

import common.dao.couchdb.CouchDBDOCFactory;
import common.dao.elastic.ElasticSearchDao;
import extract.document.program.ProgramBatchMode;
import extract.document.scene.SceneBatchMode;
import extract.document.sequence.SequenceBatchMode;
import extract.document.shot.ShotBatchMode;
import extract.document.video.VideoBatchMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by Common on 9/10/16.
 */
public class DOCBatchRun {

    static final Logger logger = LoggerFactory.getLogger(DOCBatchRun.class);

    public void importCouchDB(){
        // 0) video
        VideoBatchMode video = new VideoBatchMode(new CouchDBDOCFactory(), new ElasticSearchDao());
        video.traversalCouchDB();
        logger.info("[BatchRun] traversal video db success!");

        // 1) program
        ProgramBatchMode program = new ProgramBatchMode(new CouchDBDOCFactory(), new ElasticSearchDao());
        program.traversalCouchDB();
        logger.info("[BatchRun] traversal program db success!");

        // 2) sequence
        SequenceBatchMode sequence = new SequenceBatchMode(new CouchDBDOCFactory(), new ElasticSearchDao());
        sequence.traversalCouchDB();
        logger.info("[BatchRun] traversal sequence db success!");

        // 3) scene
        SceneBatchMode scene = new SceneBatchMode(new CouchDBDOCFactory(), new ElasticSearchDao());
        scene.traversalCouchDB();
        logger.info("[BatchRun] traversal scene db success!");

        // 4) shot
        ShotBatchMode shot = new ShotBatchMode(new CouchDBDOCFactory(), new ElasticSearchDao());
        shot.traversalCouchDB();
        logger.info("[BatchRun] traversal shot db success!");


    }



    public static void cmdUsage(){
        System.err.println("Usage: BatchRun [ cleanup | create | import ] ");
        System.out.println("- cleanup : clean up graph, delete all schema and data!");
        System.out.println("- create  : create schema and index of graph. need to cleanup graph first!");
        System.out.println("- import  : import data from couchdb, and transform it to graph!");
        System.exit(1);
    }


    /******************************************
     *
     * @param args
     */
    public static void main(String[] args){
        final String CLEANUP = "cleanup";
        final String CREATE  = "create";
        final String IMPORT  = "import";
        if (null == args || 1 != args.length) {
            cmdUsage();
        }
        String cmd = args[0];
        if(cmd.equals( CLEANUP )){
            //new BatchRun().cleanUpGraph();
        }
        else if(cmd.equals( CREATE )){
            //new BatchRun().createSchemaIndex();
        }
        else if(cmd.equals( IMPORT )){
            new DOCBatchRun().importCouchDB();
        }
        else{
            cmdUsage();
        }
        System.exit(1);
    }
}
